package com.shell.customer.base.rx;

import com.shell.customer.base.CusEvent;
import com.shell.customer.base.service.CusExtraService;
import com.shell.customer.base.vo.CusRecVo;
import com.shell.customer.po.CusExtra;
import com.shell.feign.PubUserFeign;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.governor.user.po.PubUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UpdateCusExtraSubscriber extends OnErrorNotImplementedSubscriber<CusEvent> {
	@Autowired
	private CusExtraService cusExtraService;
	@Autowired
	private PubUserFeign userFeign;

	public void onApplicationEvent(CusEvent event) {
		CusRecVo cusVo = event.getCusRecVo();
		CusExtra cusExtra = new CusExtra();

		String approverId = CommonDataUtil.getCurEntId();
		PubUser pubUser = this.userFeign.selectByKey(CommonDataUtil.getUserId());

		cusExtra.setApproverId(approverId);
		cusExtra.setInviterCusId(approverId);
		cusExtra.setCusId(cusVo.getCusId());
		cusExtra.setInviterId(pubUser.getUserId());
		cusExtra.setInviterName(pubUser.getUserName());
		cusExtra.setInviterPhone(pubUser.getPhoneNo());
		this.cusExtraService.saveOrUpdate(cusExtra);
	}
}
